package com.ruoyi.system.service.vantservice.orderservice.impl;

import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderChange;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderChangePicture;
import com.ruoyi.system.mapper.vant.order.ApiOrderChangeMapper;
import com.ruoyi.system.mapper.vant.order.ApiOrderChangePictureMapper;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderChangeService;
import com.ruoyi.system.utils.IdentifiedGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by 惠普 on 2020/12/28 14:24
 */
@Service("apiOrderChangeService")
public class ApiOrderChangeServiceImpl implements ApiOrderChangeService {
    @Resource
    private ApiOrderChangeMapper apiOrderChangeMapper;
    @Resource
    private ApiOrderChangePictureMapper apiOrderChangePictureMapper;

    /**
     * 添加退货信息
     * @param orderChange
     * @return
     */
    @Override
    public int addOrderChange(OrderChange orderChange) {
        int row = 0;
        OrderChange orderChange1 = apiOrderChangeMapper.selectOrderChangeByOrderId(orderChange.getOrderId());
        if(orderChange1==null){
            int u = IdentifiedGenerator.Num();
            orderChange.setOrderChangePicture(u);
            row = apiOrderChangeMapper.addOrderChange(orderChange);
            if(row == 1){
                OrderChangePicture orderChangePicture = new OrderChangePicture();
                orderChangePicture.setOrderChangePictureUuid(u);
                if(orderChange.getImg0()!=null){
                    orderChangePicture.setOrderChangePictureUrl(orderChange.getImg0());
                    apiOrderChangePictureMapper.addOrderChangePicture(orderChangePicture);
                }
                if(orderChange.getImg1()!=null){
                    orderChangePicture.setOrderChangePictureUrl(orderChange.getImg1());
                    apiOrderChangePictureMapper.addOrderChangePicture(orderChangePicture);
                }
                if(orderChange.getImg2()!=null){
                    orderChangePicture.setOrderChangePictureUrl(orderChange.getImg2());
                    apiOrderChangePictureMapper.addOrderChangePicture(orderChangePicture);
                }
                if(orderChange.getImg3()!=null){
                    orderChangePicture.setOrderChangePictureUrl(orderChange.getImg3());
                    apiOrderChangePictureMapper.addOrderChangePicture(orderChangePicture);
                }
            }
            return row;
        }else {
            row = 2;
            return row;
        }
    }

    /**
     * 根据订单id查询退货表数据
     * @param orderId
     * @return
     */
    @Override
    public OrderChange selectOrderChangeByOrderId(Integer orderId) {
        return apiOrderChangeMapper.selectOrderChangeByOrderId(orderId);
    }

}
